package com.bdqn.dao;

import com.bdqn.comm.SysUserVo;
import com.bdqn.pojo.SysUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SysUserRepository extends JpaRepository<SysUser,Long> {

    /**
     * 测试按用户名模糊查询
     * @param usrName
     * @return
     */
    List<SysUser> findByUsrNameLike(String usrName);

    /**
     *根据角色编号查询
     * @param roleId
     * @return
     */
    @Query(value = "select u from SysUser u where u.usrRoleId=?1",nativeQuery = true)
    List<SysUser> findByRoleId(Long roleId);

    /**
     * 分页查询
     * @param roleId
     * @param pageable
     * @return
     */
    @Query("select u from SysUser u where u.usrRoleId=?1")
    Page<SysUser> findPageByUsrRoleId(Long roleId, Pageable pageable);

    /**
     *
     * @param sysUserSpecification
     * @param pageable
     * @return
     */
    Page<SysUser> findAll(Specification<SysUser> sysUserSpecification, Pageable pageable);

    @Query("select u.usrId as usrId, u.usrName as usrName, u.usrPassword as usrPassword,u.usrRoleId as usrRoleId, u.usrFlag as usrFlag, r.roleName as roleName from SysUser u, SysRole r where u.usrRoleId=r.roleId and u.usrId=?1")
    SysUserVo getSysUserInfo(Long usrId);
}
